<?php
class indexControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function onDefault(){
		if($_SERVER['HTTP_REFERER']=='' || preg_match("/m=login/",$_SERVER['HTTP_REFERER'])){
			$this->onMain();
		}else{
			$this->onList();
		}
	}
	public function onMain(){
		//今日订单
		$key="appshop_index_".SHOPID;
		if(!$cache=cache()->get($key)){
			$neworder=M("shop_order")->selectOne(array(
				"where"=>" shopid=".SHOPID." AND status=0 ",
				"fields"=>" count(order_id) as c"
			));
			$dayorder=M("stat_shoporder_day")->selectRow("shopid=".SHOPID." AND k='shop' AND kday='".date("Ymd")."' ");
			$monthorder=M("stat_shoporder_month")->selectRow("shopid=".SHOPID." AND k='shop' AND kmonth='".date("Ym")."' ");
			$ssnum=M("shop_order")->getOne("select count(*) from ".table('shop_order')." WHERE shopid=".SHOPID." group by sushe ");
			 
			$allmoney=M("stat_shoporder_month")->selectOne(array(
				"where"=>" shopid=".SHOPID." AND k='shop' ",
				"fields"=>" sum(money) as money"
			));
			
			$allbalance=M("stat_shoporder_month")->selectOne(array(
				"where"=>" shopid=".SHOPID." AND k='shop' ",
				"fields"=>" sum(balance) as money"
			));  
			$newuser=M("shop_user")->selectOne(array(
				"where"=>" shopid=".SHOPID." AND kday='".date("Y-m-d")."' ",
				"fields"=>" count(*) as ct "
			));
			$monthuser=M("shop_user")->selectOne(array(
				"where"=>" shopid=".SHOPID." AND kday like '".date("Y-m")."%'",
				"fields"=>" count(*) as ct "
			));
			
			$alluser=M("shop_user")->selectOne(array(
				"where"=>" shopid=".SHOPID." ",
				"fields"=>" count(*) as ct "
			));
			$allordernum =M("stat_shoporder_month")->selectOne(array(
				"where"=>" shopid=".SHOPID." AND k='shop' ",
				"fields"=>" sum(ordernum) as money"
			));  
			$this->smarty->assign(array(
				"neworder"=>$neworder,
				"allbalance"=>$allbalance,
				"allmoney"=>$allmoney,		 
				"dayorder"=>$dayorder,
				"allordernum"=>$allordernum,
				"monthorder"=>$monthorder,
				"sushe_num"=>$ssnum,
				"wgnum"=>$wgnum,
				"newuser"=>$newuser,
				"alluser"=>$alluser,
				"monthuser"=>$monthuser,
			));
			cache()->set($key,$this->smarty->_var,1); 
		 }else{
			$this->smarty->_var=$cache;
		} 
		$this->smarty->display("index.html");
		
	}
	
	public function onList(){
		$this->smarty->display("list.html");
	}
	
	public function onProduct(){
		$this->smarty->display("product.html");
	}
}

 
?>